//接口统一管理

import requests from './requests'
import mockRequests from './mockRequests'

//三级联动接口
export const reqCategoryList = () => {
  return requests({
    url: '/product/getBaseCategoryList',
    method: 'get'
  })
}

//搜索商品api
export const reqGoodsList = (params = {}) => {
  return requests({ url: '/list', method: 'post', data: params })
}

//获取商品信息
export const reqGoodsDetail = (id) => {
  return requests({ url: '/item/' + id, method: 'get' })
}

//添加购物车||修改商品数量
export const reqAddOrChangeShop = (skuId, skuNum) => {
  return requests({ url: `/cart/addToCart/${skuId}/${skuNum}`, method: 'post' })
}

//获取该用户的购物车列表
export const reqGetCartList = () => requests({ url: '/cart/cartList' })

//购物车操作--切换商品选中状态
export const reqChangeGoodsSelect = (skuID, isChecked) =>
  requests({
    url: `/cart/checkCart/${skuID}/${isChecked}`,
    method: 'get'
  })

//购物车操作--删除购物车商品
export const reqDelGoodsFromShopcart = (skuId) =>
  requests({ url: `/cart/deleteCart/${skuId}`, method: 'delete' })

// 注册
export const reqRegister = (data) =>
  requests({
    url: '/user/passport/register',
    method: 'post',
    data
  })

//获取验证码
export const reqGetSecurityCode = (phone) =>
  requests({
    url: `/user/passport/sendCode/${phone}`,
    method: 'get'
  })

//登录
export const reqLogin = (data) =>
  requests({ url: '/user/passport/login', method: 'post', data })

// 获取用户信息
export const reqGetUserInfo = () =>
  requests({ url: '/user/passport/auth/getUserInfo', method: 'get' })

//退出登陆
export const reqLogout = () =>
  requests({ url: '/user/passport/logout', method: 'get' })

// 根据购物车获取该次订单商品等信息
export const reqGetShopCartOrder = () =>
  requests({ url: '/order/auth/trade', method: 'get' })

// 获取用户地址
export const reqGetUserAdress = () =>
  requests({ url: '/user/userAddress/auth/findUserAddressList', method: 'get' })

// 提交该次订单
export const reqSendOrder = (tradeNo, data) =>
  requests({
    url: `/order/auth/submitOrder?tradeNo=${tradeNo}`,
    method: 'post',
    data
  })

// 获取支付码
export const reqGetPayQrcode = (orderId) =>
  requests({ url: `/payment/weixin/createNative/${orderId}`, method: 'get' })

// 根据订单号查询支付情况
export const reqQueryPay = (orderId) =>
  requests({
    url: `/payment/weixin/queryPayStatus/${orderId}`,
    method: 'get'
  })

// 获取用户订单列表
export const reqgetOrderList = (page, limit) =>
  requests({
    url: `/order/auth/${page}/${limit}`,
    method: 'get'
  })

// ===mock 接口===
// 获取轮播图
export const reqBannerList = () => {
  return mockRequests({ url: '/banner', method: 'get' })
}

//获取楼层数据
export const reqFloorList = () => {
  return mockRequests({ url: '/floor', method: 'get' })
}
